import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
// import store from '../store'

Vue.use(VueRouter)


const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/publish',
    meta: {
      needLogin: true
    },
    component: () => import("../views/publish")
  },
  {
    path: '/login',
    component: () => import("../views/Login")
  },
  {
    path: '/mine',
    meta: {
      needLogin: true
    },
    component: () => import("../views/mine")
  },
  {
    path: '/detail',
    component: () => import('../views/detail')
  },
  {
    path: '/search',
    component: () => import('../views/search')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// // 配置路由守卫
// router.beforeEach((to,from,next)=>{
//   if(to.meta.needLogin){
//     if(store.state.isLogin){
//       next()
//     }else {
//       next('/')
//     }
//   }else{
//     next()
//   }
// })

export default router
